package com.hotpot.comm.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * 描述:基础controller
 * 
 * @author myx
 * @date 2017年7月10日 下午1:55:52
 */
public class BaseController {
	protected HttpServletRequest request;

	protected HttpServletResponse response;

	protected HttpSession session;

	/**
	 * 方法描述：得到PageData
	 * @return
	 * @return: ParamMap
	 */
	public ParamMap getTransmitMap() {
		return new ParamMap(this.getRequest());
	}

	/**
	 * 方法描述：得到request对象
	 * @return
	 * @return: HttpServletRequest
	 */
	public HttpServletRequest getRequest() {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
		return request;
	}

	/**
	 * 方法描述：
	 * @param obj
	 * @return
	 * @return: Result
	 */
	protected R renderParamError(Object obj) {
		R result = new R(403, obj, "参数传递错误", null);
		return result;
	}

	/**
	 * 方法描述：渲染失败数据
	 * @return
	 * @return: Result
	 */
	protected R renderError() {
		R result = new R(500, null, "服务异常", null);
		return result;
	}

	/**
	 * 方法描述：渲染成功数据
	 * @param obj 需要返回的对象
	 * @return
	 * @return: Result
	 */
	protected R renderSuccess(Object obj) {
		R result = new R(200, obj, "成功", null);
		return result;
	}

	/**
	 * 方法描述：渲染其他数据
	 * @param returnCode  返回状态码
	 * @param obj 返回数据
	 * @param msg  返回提示信息
	 * @return
	 * @return: Result
	 */
	protected R renderOther(Integer returnCode, Object obj, String msg) {
		R result = new R(returnCode, obj, msg, null);
		return result;
	}

}
